# 89 文件的追加写入
# f = open('E:/Desktop/python.txt', 'a', encoding='UTF-8')
# f.write('wenxiaojian')
# f.flush()
# f.close()

# f = open('E:/Desktop/python.txt', 'a', encoding='UTF-8')
# f.write('\n月薪过万')
# f.close()

# 90 练习
# 打开文件得到文件对象，准备读取
# fr = open("D:/bill.txt", "r", encoding="UTF-8")
# # 打开文件得到文件对象，准备写入
# fw = open("D:/bill.txt.bak", "w", encoding="UTF-8")
# # for循环读取文件
# for line in fr:
#     line = line.strip()
#     # 判断内容，将满足的内容写出
#     if line.split(",")[4] == "测试":
#         continue  # continue进入下一次循环，这一次后面的内容就跳过了
#     # 将内容写出去
#     fw.write(line)
#     # 由于前面对内容进行了strip()的操作，所以要手动的写出换行符
#     fw.write("\n")
#
# # close2个文件对象
# fr.close()
# fw.close()  # 写出文件调用close()会自动flush()

# 91 异常
# 概念

# 92 异常的捕获
# 基本语法捕获
# try:
#     f = open('D:/abc.txt', 'r', encoding='UTF-8')
# except:
#     print('出现异常了，因为文件不存在，我将open的模式，改为W去打开')
#     f = open('D:/abc.txt', 'w', encoding='UTF-8')

# 捕获指定异常
# try:
#     print(name)
# except NameError as e:
#     print("出现了变量未定义的异常")
#     # print(e)

# 捕获多个异常
# try:
#     # print(name)
#     1 / 0
# except(NameError, ZeroDivisionError) as e:
#     print('出现了变量未定义或者除以0的异常错误')

# 捕获所有异常
# try:
#     f = open("D:/123.txt", "r", encoding="UTF-8")
# except Exception as e:
#     print('出现异常了')
#     f = open("D:/123.txt", "w", encoding="UTF-8")
# else:
#     print('好高兴,没有异常')
# finally:
#     print('我是finally,有没有异常我都要执行')
#     f.close()

# 93 异常的传递性
# def fun1():
#     print('fun1 开始执行')
#     1 / 0
#     print('fun1 结束执行')
#
#
# def fun2():
#     print('fun2 开始执行')
#     fun1()
#     print('fun2 结束执行')
#
#
# def main():
#     try:
#         fun2()
#     except Exception as e:
#         print("出现了除0的异常")
#
#
# main()

# 94 模块
# import time
#
# print("你好")
# time.sleep(5)
# print("wohao")

# from time import sleep
#
# print("你好")
# sleep(5)
# print("wohao")

# from time import *
#
# print("你好")
# sleep(5)
# print("wohao")

# import time as t
#
# print("你好")
# t.sleep(5)
# print("wohao")
#
# from time import sleep as sl
#
# print("你好")
# sl(5)
# print("我好")

# 95 自定义模块并导入
# from my_module1 import first_test
#
# first_test(1, 2)

# from my_module1 import first_test
# from my_module2 import first_test
#
# first_test(1, 2)

# from my_module1 import first_test
#
# first_test(1, 2)

# from my_module1 import first_test
#
# first_test(3, 4)
# first_test2(5, 6)

# 96 自定义python包
# import Package_test.module1
# import Package_test.module2
#
# Package_test.module1.module1()
# Package_test.module2.module2()


# 97 安装第三方包
# pip

# 98 练习
import Package_test.str_util
import Package_test.file_util

print(Package_test.str_util.str_reverse("wenxiaojiannihaoa"))
print(Package_test.str_util.substr('wenxiaojian', 1, 5))

Package_test.file_util.append_to_file("D:/python.txt", 'wenxiaojian nihao ')
Package_test.file_util.print_file_info("D:/python.txt")
